<?php class send_record extends CI_Model {

    function __construct()
    {
        parent::__construct();
    }
    
    function getsend_array($arr){
       $this->db->limit(1);
       $this->db->where($arr);
       $this->db->order_by("send_id", "desc");
       $query = $this->db->get('send_record');
       $result = $query->result(); 
       return $result;
    }
    function select_by_version($update,$arr){
      if($update==0){
      	$this->db->where_in('version_id', $arr);
      }else{
      	$this->db->where_not_in('version_id', $arr);
      }
       $query = $this->db->get('send_record');       
       $result = $query->result(); 
       return $result;
    }
    
    function insert($data){
       $result = $this->db->insert('send_record',$data);
       return $result;
    }
    
    function select($id,$num="",$offset=""){
       $this->db->limit($num,$offset);	
       if($id!=""){
       	  $this->db->where($id);
       }
       $this->db->order_by('send_id','desc');
       $query = $this->db->get('send_record');
       
       $result = $query->result(); 
       return $result;
    }
    
    
    function select_by_array($array){
       $this->db->where($array);
       $this->db->order_by('send_id','desc');
       $query = $this->db->get('send_record');       
       $result = $query->result(); 
       return $result;
    }
    
    function getcom($id){
    	$this->db->select('company_id');
        $this->db->where(array('category_id'=>$id));
    	$this->db->distinct();
        $query = $this->db->get('send_record');
        $result = $query->result(); 
        return $result;
    }
    
    function select_join($ar){
       $this->db->select('*');
       $this->db->where($ar);
	   $this->db->from('send_record');
	   $this->db->join('category', 'send_record.category_id = category.category_id');
       $query = $this->db->get();
       $result = $query->result(); 
       return $result;
    
    }
    
    function getlast($version_id,$id){
       $this->db->where(array('category_id'=>$id,'version_id'=>$version_id));
       $this->db->select_sum('count');
       $query = $this->db->get('send_record');
       $result = $query->result(); 
       return $result;
    }
    function getlast_fo($version_id,$id){

       $this->db->where('category_id',$id);
       $this->db->where('version_id !=',$version_id);
       $this->db->select_sum('count');
       $query = $this->db->get('send');
       $result = $query->result(); 
       return $result;
    }
    
    function getcount($id,$version_id=''){
        $where['category_id']=$id;
    	if($version_id!=""){
    	 $where['version_id']=$version_id;
    	}
        $this->db->where($where);
    	$this->db->select_sum('count');
        $query = $this->db->get('send_record');
        $result = $query->result(); 
        return $result;
    }
    
    
    function update($id,$array){
       $result = $this->db->update('send_record',$array,array('s_id'=>$id));
     
       return $result;
    }
    
    
    function update_array($where,$array){
       $result = $this->db->update('send_record',$array,$where);
       //error_log($this->db->last_query(),3,'d:/sql.txt');
       return $result;
    }
    function del($id){
       $result = $this->db->delete('send_record',array('send_id'=>$id));
       return $result;
    }
}